package routers

import (
	"github.com/gin-contrib/static"
	"github.com/gin-gonic/gin"

	"github.com/gin-contrib/cors"
)

func NewRouter() *gin.Engine {
	r := gin.New()

	r.Use(cors.Default())
	r.Use(static.ServeRoot("/", "./web/dist"))
	r.Use(gin.Logger())
	r.Use(gin.Recovery())

	r.Static("/images", "./images")

	system := NewSystemApi()
	article := NewArticleApi()
	api := r.Group("/api")
	{
		api.POST("/set_path", system.SetPath)
		api.POST("/del_path", system.DelPath)
		api.GET("/paths", system.Paths)
		api.POST("/import", system.ImportSource)
		api.GET("/logs", system.WorkerLogs)

		api.GET("/articles", article.List)
		api.GET("/articles_all", article.ListAll)
	}
	return r
}
